package com.jiashihui.server1.validator;

import com.jiashihui.server1.annotation.Min;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
*describe: 
*
*@author jiashihui
*@date 2018/11/20
*/
public class MinValidator implements ConstraintValidator<Min, Integer> {
    private int minValue;
    @Override
    public void initialize(Min min) {
        //把Min限制类型的属性value赋值给当前ConstraintValidator的成员变量minValue
        minValue = min.value();
    }
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext arg1) {
        //在这里我们就可以通过当前ConstraintValidator的成员变量minValue访问到当前限制类型Min的value属性了
        return value >= minValue;
    }
}
